package com.lagou.edu.service.impl;

import com.lagou.edu.dao.AuthCodeDao;
import com.lagou.edu.dao.TokenDao;
import com.lagou.edu.pojo.AuthCode;
import com.lagou.edu.pojo.Token;
import com.lagou.edu.service.ValicateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

/**
 * @author lyj
 * @Title: ValicateServiceImpl
 * @ProjectName homework-parent
 * @Description: TODO
 * @date 2021/1/2 23:37
 */
@Service
public class ValicateServiceImpl implements ValicateService {
    @Autowired
    private AuthCodeDao authCodeDao;
    @Autowired
    private TokenDao tokenDao;

    @Override
    public boolean saveAuthCode(AuthCode authCode) {
         authCodeDao.save(authCode);
        return true;
    }

    @Override
    public boolean saveToken(Token token) {
        tokenDao.save(token);
        return true;
    }

    @Override
    public AuthCode getAuthCodeByEmail(String email) {
        AuthCode authCode=new AuthCode();
        authCode.setEmail(email);
        Example<AuthCode> example = Example.of(authCode);
        return authCodeDao.findOne(example).get();
    }

    @Override
    public Token getTokenByEmail(String email) {
        Token token=new Token();
        token.setEmail(email);
        Example<Token> example = Example.of(token);
        return tokenDao.findOne(example).get();
    }
}
